<template>
  <t-dialog :header="`${header}【当前已勾选${selectedRowKeys.concat(selectedRowKeys2).length}】【待评审项目数${projectList.length}】`"
    @confirm="onSubmit" :confirmBtn="{
    content: loading ? '提交中...' : '确认',
    theme: 'primary',
    loading: loading,
  }" :visible.sync="visible" :onClose="closeDialog" :closeOnOverlayClick="false" width="80%" top="5%">
    <div style="height: 65vh">
      <!-- <div style="display: flex;font-weight: bold;justify-content: center;align-items: center;font-size: 30px;padding: 30px">
        推荐项目列表
        <t-button @click="getSmartList" style="margin-left: 20px" variant="outline" theme="primary">
          <t-icon name="refresh" slot="icon"/>
          刷新
        </t-button>
      </div>
      <t-table row-key="id" :columns="formData.reviewType == 5 ? columns2 : columns" :data="data2" :selected-row-keys="selectedRowKeys2"
               :loading="dataLoading2"
               @select-change="(val)=>{selectedRowKeys2=val}">
        <template #[`subjectClassification`]="{row}">
          {{ row.subjectClassification | filterByDict(dict.type.subject_classification) }}
        </template>
<template #[`projectType`]="{row}">
          {{ row.projectType | filterByDict(dict.type.project_type) }}
        </template>
<template #isFinishRevision={row}>
          <t-tag :theme="row.isFinishRevision == 1 ? 'success' : 'warning'" variant="light">
            {{ row.isFinishRevision == 1 ? '是' : '否' }}
          </t-tag>
        </template>
<template #op="{row}">
          <t-button v-if="row.version === '2024'" @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.editOpen=false;dialog.open_item_detail=true" size="small" variant="text" class="t-button-link">
            <t-icon name="info-circle" slot="icon"/>
            详情
          </t-button>
          <t-button v-else @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.editOpen=false;dialog.open_detail=true" size="small" variant="text" class="t-button-link">
            <t-icon name="info-circle" slot="icon"/>
            详情
          </t-button>
        </template>
</t-table> -->
      <div style="display: flex;font-weight: bold;justify-content: center;font-size: 30px;padding: 30px">
        待评审科普站列表
      </div>
      <t-table row-key="id" :columns="columns" :data="data" :selected-row-keys="selectedRowKeys" :loading="dataLoading"
        @select-change="(val) => { selectedRowKeys = val }">
        <template #baseStatus="{ row }">
          <t-tag @click="dialog.header = '审批记录'; dialog.objId = row.id; dialog.open_approve_list = true" class="cursor-pointer"
            :theme="handleTheme(row.baseStatus, dict.type.base_status)" variant="light">
            {{ row.baseStatus | filterByDict(dict.type.base_status) }}
          </t-tag>
        </template>
        <template #op="{ row }">
          <t-button v-if="row.version === '2024'"
            @click="dialog.header = row.projectName; dialog.objId = row.id; dialog.editOpen = false; dialog.open_item_detail = true"
            size="small" variant="text" class="t-button-link">
            <t-icon name="info-circle" slot="icon" />
            详情
          </t-button>
          <t-button v-else
            @click="dialog.header = row.projectName; dialog.objId = row.id; dialog.editOpen = false; dialog.open_detail = true"
            size="small" variant="text" class="t-button-link">
            <t-icon name="info-circle" slot="icon" />
            详情
          </t-button>
        </template>
      </t-table>
    </div>
    <base-detail-dialog :header="dialog.header" :obj-id="dialog.objId" :visible.sync="dialog.open_detail"
      v-if="dialog.open_detail"></base-detail-dialog>

  </t-dialog>
</template>

<script>
import BaseDetailDialog from "@/pages/kpzh/science-base/components/base-detail-dialog.vue";

export default {
  name: "select-project",
  dicts: ["subject_classification", "project_type", "base_status"],
  components: {
    BaseDetailDialog
  },
  props: {
    header: {
      type: String,
      default: ''
    },
    formData: {
      type: Object,
      default: () => ({})
    },
    projectList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      loading: false,
      data2: [],
      dataLoading2: false,
      selectedRowKeys2: [],
      dialog: {
        header: "",
        objId: 0,
        open_detail: false,
        editOpen: true,
        open_item_detail: false,
      },
      selectedRowKeys: [],
      queryParams: {
        reviewType: '',
        pageNum: 1,
        pageSize: 10,
        dateRange: []
      },
      data: [],
      dataLoading: false,
      pagination: {
        defaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        showPageSize: false,
        showFirstAndLastPageBtn: false,
      },

      columns: [
        {
          colKey: 'row-select',
          type: 'multiple',
          className: 'demo-multiple-select-cell',
          width: 64,
        },
        {
          colKey: "name",
          title: "科普站名称",
          align: "center",
          width: 220

        },
        {
          colKey: "declareDeptName",
          title: "申报单位",
          align: "center",
        },
        {
          colKey: "address",
          title: "科普站地址",
          align: "center",
        },
        {
          colKey: "baseType",
          title: "基地类型",
          align: "center",
        },
        {
          colKey: "legalPerson",
          title: "负责人",
          align: "center",
        },
        // {
        //   colKey: "communicateAddress",
        //   title: "通讯地址",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "postCode",
        //   title: "邮编",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "legalPerson",
        //   title: "科普站负责人",
        //   align: "center",
        //   width: 160,
        // },
        {
          colKey: "linkerPerson",
          title: "联系人",
          align: "center",
        },
        {
          colKey: "mobilePhone",
          title: "移动电话",
          align: "center",
        },
        // {
        //   colKey: "fixedPhone",
        //   title: "固定电话",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "fax",
        //   title: "传真",
        //   align: "center",
        //   width: 160,
        // },
        {
          colKey: "email",
          title: "公共邮箱",
          align: "center",
        },
        // {
        //   colKey: "workPlan",
        //   title: "交通运输科普工作管理制度、规划或计划 有或无",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "indoorVenues",
        //   title: "室内场馆面积/m2",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "outdoorVenues",
        //   title: "室外场馆面积/m2",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "lectureHall",
        //   title: "影视报告厅面积/m2",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "openDays",
        //   title: "每年对外开放时间/天",
        //   align: "center",
        //   width: 160,
        // },
        // {
        //   colKey: "receptionPerson",
        //   title: "每年接待公众/人次",
        //   align: "center",
        //   width: 160,
        //   sorter: true,
        // },
        {
          colKey: "baseStatus",
          title: "科普站状态",
          align: "center",
          sorter: true,
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 240,
          fixed: 'right'
        },
      ],

      columns2: [
        {
          colKey: 'row-select',
          type: 'multiple',
          className: 'demo-multiple-select-cell',
          width: 64,
        },
        {
          colKey: "projectName",
          title: "项目名称",
          align: "center",
        },
        {
          colKey: "projectLeaderName",
          title: "负责人",
          align: "center",
          width: 100
        },
        {
          colKey: "declareDeptName",
          title: "承担单位",
          align: "center",
          width: 180,
        },
        {
          colKey: "adviceFunding",
          title: "建议经费总概算",
          align: "center",
          width: 140
        },
        {
          colKey: "subsidyFunding",
          title: import.meta.env.VITE_SITE_TAG === 'jtt' ? "厅拨经费" : `集团补助经费`,
          align: "center",
          width: 140
        },
        {
          colKey: "projectCategoryName",
          title: "计划类别",
          align: "center",
          width: 120
        },
        {
          colKey: "subjectClassification",
          title: "学科分类",
          align: "center",
          width: 100
        },
        {
          colKey: "projectType",
          title: "项目类型",
          align: "center",
          width: 120
        },
        // {
        //   colKey: "createTime",
        //   title: "申报时间",
        //   align: "center",
        //   width: 200
        // },
        {
          colKey: "isFinishRevision",
          title: "是否完成修改",
          align: "center",
          width: 60
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      visible: true,
    }
  },
  watch: {
    formData: {
      immediate: true,
      handler (val) {
        if (val.id) {
          this.getList();
          // this.getSmartList();
        }
      }
    }
  },
  methods: {
    getList () {
      this.dataLoading = true;
      // this.queryParams.pageNum = this.pagination.current || 1;
      this.queryParams.reviewType = this.formData.reviewType;
      this.queryParams.teamId = this.formData.id;
      this.$api.kpzh.review.teamProjectListByReviewType(this.queryParams).then((res) => {
        this.data = res.data;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false
        this.$message.error(e.toString());
      });
    },
    // getSmartList(){
    //   this.dataLoading2= true;
    //   // this.queryParams.pageNum = this.pagination.current || 1;
    //   this.queryParams.reviewType = this.formData.reviewType;
    //   this.queryParams.teamId = this.formData.id;
    //   this.$api.kpzh.review.teamSmartProjectListByReviewType(this.queryParams).then((res) => {
    //     this.data2 = res.data;
    //     this.dataLoading2 = false;
    //   }).catch((e) => {
    //     this.dataLoading2=false
    //     this.$message.error(e.toString());
    //   });
    // },
    onSubmit () {
      if (this.selectedRowKeys.concat(this.selectedRowKeys2).length === 0) {
        this.$message.error('请选择项目')
        return false
      }
      const businessId = this.selectedRowKeys.concat(this.selectedRowKeys2).map(val => ({
        teamId: this.formData.id,
        businessId: val,
        reviewType: this.formData.reviewType
      }))
      this.loading = true;
      this.$api.kpzh.review.teamProjectAddList(businessId).then((res) => {
        // 初始化
        this.$message.success("选择成功");
        this.$emit("reload");
        this.$emit("update:visible", false);
        this.loading = false;
      }).catch((e) => {
        this.loading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog () {
      this.$emit("update:visible", false);
    },

  }
}
</script>

<style scoped>
.overlay-options {
  display: inline-block;
  font-size: 20px;
}
</style>
